#include "common.h"
#include "fs.h"
#include "memory.h"

void ramdisk_read(void *buf, off_t offset, size_t len);

size_t get_ramdisk_size();

#define DEFAULT_ENTRY ((void *)0x8048000)

uintptr_t loader(_Protect *as, const char *filename)
{
  int fd = fs_open(filename, 0, 0);
  size_t size = fs_filesz(fd);
  void* va=0;void* pa=0;
  while((uint32_t)va<size)
  {
    pa=new_page();
    _map(as,(uint32_t)va+DEFAULT_ENTRY,pa);
    fs_read(fd, pa, PGSIZE);
    va+=PGSIZE;
  }
  fs_close(fd);
  return (uintptr_t)DEFAULT_ENTRY;
}
